﻿using System;
using System.Data;
using PCSComProduct.Items.DS;
using System.Transactions;
using PCSComUtils.DataContext;
using System.Collections.Generic;
using PCSComUtils.DataAccess;
using System.Text;

namespace PCSComProduct.Items.BO
{
    public class ValueForWorkingTimeBO
    {
        public bool Insert(ITM_ValueForWorkingTimeMaster objMaster, List<ITM_ValueForWorkingTimeDetail> listDetail)
        {
            bool ret = true;
            using (var trans = new TransactionScope())
            {
                using (var db = new PCSDataContext(Utils.Instance.ConnectionString))
                {
                    try
                    {
                        db.ITM_ValueForWorkingTimeMasters.InsertOnSubmit(objMaster);
                        db.SubmitChanges();
                        foreach (ITM_ValueForWorkingTimeDetail objDetail in listDetail)
                            objDetail.ValueForWorkingTimeMasterID = objMaster.ValueForWorkingTimeMasterID;
                        db.ITM_ValueForWorkingTimeDetails.InsertAllOnSubmit(listDetail);
                        db.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        ret = false;
                        Transaction.Current.Rollback();
                        //throw ex;
                    }
                    finally { trans.Complete(); }
                    return ret;
                }
            }
        }
        public bool Delete(int iMasterID)
        {
            bool ret = true;
            using (var trans = new TransactionScope())
            {
                using (var db = new PCSDataContext(Utils.Instance.ConnectionString))
                {
                    try
                    {
                        StringBuilder strCommand = new StringBuilder();
                        strCommand.Append("DELETE FROM ITM_ValueForWorkingTimeDetail WHERE ValueForWorkingTimeMasterID='");
                        strCommand.Append(iMasterID);
                        strCommand.Append("' ");
                        strCommand.Append("DELETE FROM ITM_ValueForWorkingTimeMaster WHERE ValueForWorkingTimeMasterID='");
                        strCommand.Append(iMasterID);
                        strCommand.Append("' ");
                        db.ExecuteCommand(strCommand.ToString());
                    }
                    catch (Exception ex)
                    {
                        ret = false;
                        Transaction.Current.Rollback();
                        //throw ex;
                    }
                    finally { trans.Complete(); }
                    return ret;
                }
            }
        }
        public DataSet GetData(int iMaserID)
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            return objDS.GetData(iMaserID);
        }
        public void RunScript(int ID)
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            objDS.RunScript(ID);
        }
        public void RunScript2()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            objDS.RunScript2();
        }
        public void RunScript3()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            objDS.RunScript3();
        }
        public void RunScript4()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            objDS.RunScript4();
        }
        public void RunScript5()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            objDS.RunScript5();
        }
        public void RunScript6()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            objDS.RunScript6();
        }
        public void RunScript7()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            objDS.RunScript7();
        }
        public void RunScript8()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            objDS.RunScript8();
        }

        public DataSet GetListKTMaVTHH()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            return objDS.GetListKTMaVTHH();
        }
        public DataSet GetListTrungSP()
        {
            ValueForWorkingTimeDS objDS = new ValueForWorkingTimeDS();
            return objDS.GetListTrungSP();
        }
    }
}
